<?php

include_once 'Controller.php';
include_once 'models/User.php';
include_once 'controllers/UserFavs.php';

class User extends Controller {
  private $pl;
  
  public function User($attr=null){ 
    $this->model = new User_($attr);
    //echo "<h1>{$this->getAttribute('id')}</h1>";
    $this->pl = new UserFavs(array(user_id =>$this->getAttribute('id')));
  }
  
  public function getPlayList(){
  	$this->result = $this->pl->get()->result();
    return $this;
  }
  
  public function getDetails() {
  	$result = $this->model()->getDetails();
    
    $fb_details = $this->getFBDetails($result->fb_id);
    $result->picture = $fb_details;
    $this->result = $result;
        
    return $this;
  }

  private function getFBDetails($fb_id) {
  	
    if($fb_id == Session::factory()->getFbUserId()){
      $fb_details = Session::factory()->getUserFbDetails();
      return $fb_details['pic'];
    }
    
  	if(!$facebook)
      $facebook = new Facebook(FB_APPKEY, FB_APPSECRET);
    $fb_details = $facebook->api_client->users_getInfo(array($fb_id), array('pic'));
    
    return $fb_details[0]['pic'];
  }

}

?>
